import os
from posix import listdir

path=os.path.dirname(__file__)
README=os.path.join(path,'README.md')
with open(README,'r',encoding='utf-8') as f:
    string=''
    while True:
        a=f.readline()
        if a.startswith('## 思维导图'):
            string+=a
            break
        else:
            string+=a
with open(README,'w',encoding='utf-8') as f:      
    folders=[]
    for i in os.listdir(path):
        if os.path.isdir(i):
            if not i.startswith('.'):
                folders.append(i)
    for name in folders:
        for i in listdir(os.path.join(path,name)):
            end=i.split('.')[-1]
            if end in ['jpeg','jpg','gif','png']:
                string+=f'  \n### {name}'
                string+=f'  \n![]({name}/{i})'
                break
    f.write(string)
            
            